package com.ws.lv.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ws.lv.bean.Save;
import com.ws.lv.service.SaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/save")
public class SaveController {

    @Autowired
    SaveService saveService;

    // 跳转到收藏信息页面
    @RequestMapping("/selectSave")
    public String selectSave(String user_name, String route_name, Integer currentPage, Model model){
        System.out.println("跳转到收藏信息页面");
        PageHelper pageHelper = new PageHelper();//分页帮助类
        if (currentPage == null){
            pageHelper.startPage(1, 10);
        }else {
            pageHelper.startPage(currentPage, 10);
        }
        List<Save> saves = saveService.selectSaves(user_name, route_name);
        System.out.println("收藏信息：" + saves);
        PageInfo pageInfo = new PageInfo(saves);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("currentPage", currentPage);
        model.addAttribute("user_name", user_name);
        model.addAttribute("route_name", route_name);
        return "adminpage/save/list";
    }

}
